# -*- coding: utf-8 -*-
from odoo import models, fields, api, SUPERUSER_ID, _


class ResUsers(models.Model):
    _inherit = 'res.users'

    menu_position = fields.Selection([
        ('top', _('Top Navbar')),
        ('sidebar', _('Left Sidebar')),
    ], string=_('Menu Position'), 
        default='top',
        groups='base.group_user',  # 所有内部用户可见
        help=_('Choose where to display the main menu'))
    
    enable_multi_tab = fields.Boolean(
        string=_('Enable Multi-Tab Mode'),
        default=False,
        groups='base.group_user',  # 所有内部用户可见
        help=_('Allow opening multiple pages simultaneously like browser tabs')
    )

    # Odoo 18 的方式：使用 SELF_READABLE_FIELDS 和 SELF_WRITEABLE_FIELDS
    @property
    def SELF_READABLE_FIELDS(self):
        """允许用户读取自己的这些字段"""
        return super().SELF_READABLE_FIELDS + ['menu_position', 'enable_multi_tab']

    @property
    def SELF_WRITEABLE_FIELDS(self):
        """允许用户修改自己的这些字段"""
        return super().SELF_WRITEABLE_FIELDS + ['menu_position', 'enable_multi_tab']
    
    def write(self, vals):
        """确保用户可以修改自己的配置"""
        # 如果是用户自己修改自己的记录，允许修改这些字段
        if self._uid != SUPERUSER_ID:
            for user in self:
                if user.id == self._uid:
                    # 用户修改自己的记录，允许
                    pass
        return super().write(vals)

